﻿using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Tryit.Controls
{
    /// <summary>
    /// ImageWithText.xaml 的交互逻辑
    /// </summary>
    public partial class ImageWithText : UserControl

    {
        #region 注册属性
        public static readonly DependencyProperty GameModeProperty = DependencyProperty.Register("GameMode", typeof(string), typeof(ImageWithText), new PropertyMetadata(OnValueChanged));
        public static readonly DependencyProperty RankedProperty = DependencyProperty.Register("Ranked", typeof(string), typeof(ImageWithText), new PropertyMetadata(OnValueChanged));
        public static readonly DependencyProperty WinPercentageProperty = DependencyProperty.Register("WinPercentage", typeof(string), typeof(ImageWithText), new PropertyMetadata(OnValueChanged));
        public string GameMode
        {
            get { return (string)GetValue(GameModeProperty); }
            set { SetValue(GameModeProperty, value); }
        }
        public string Ranked
        {
            get { return (string)GetValue(RankedProperty); }
            set { SetValue(RankedProperty, value); }
        }
        public string WinPercentage
        {
            get { return (string)GetValue(WinPercentageProperty); }
            set { SetValue(WinPercentageProperty, value); }
        }
        #endregion
        public ImageWithText()
        {
            InitializeComponent();
            BindData();
        }
        private void BindData()
        {
            Gamemode.Text = GameMode;
            Rank.Text = Ranked;
            Winpercentage.Text = WinPercentage;
        }
        private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as ImageWithText;
            var newValue = e.NewValue as string;
            if (e.Property == GameModeProperty)
            {
                control.Gamemode.Text = newValue;
            }
            else if (e.Property == RankedProperty)
            {
                control.Rank.Text = newValue;
            }
            else if (e.Property == WinPercentageProperty)
            {
                control.Winpercentage.Text = newValue;
            }
        }

    }
}
